Copying a Table with DXL

Hello,

I'm trying to write a DXL script to copy all Tables from Module src to Module tar.  I'm wondering if there's a copyTable(Table t, Object parent) function somewhere that does the same thing as using the mouse to drag and drop the table header between modules.  I've searched through the DXL reference manual and on the internet and can't seem to find anything.

 

My current plan is to write a function that

 - Iterates through the src table rows/cells to get a count of the table dimensions

 - Creates a new table in tar with create(rowNum, colNum)

 - For every cell in src table, copy all attributes to the same cell in the tar table

 

It seems strange to me that I'd have to write this manually when the nicely encapsulated functionality exists with the mouse and keyboard.  Does anyone know an easier way?

 

Thanks

 


brh2113 - Mon Aug 05 10:52:38 EDT 2013

Re: Copying a Table with DXL
GregM_dxler - Mon Aug 05 13:58:39 EDT 2013

Hi,

How about setting the module to not show table cells first and then just copy and paste the table header object?  Since table cells are all children of the header object, they should all get copied.  To determine if table cells are showing you can use the command tableContents(Module m) and then tableContents(false) to hide the table cells.  Maybe just hide the table cells either way is good enough.

Greg

Re: Copying a Table with DXL
brh2113 - Mon Aug 05 14:47:40 EDT 2013

GregM_dxler - Mon Aug 05 13:58:39 EDT 2013

Hi,

How about setting the module to not show table cells first and then just copy and paste the table header object?  Since table cells are all children of the header object, they should all get copied.  To determine if table cells are showing you can use the command tableContents(Module m) and then tableContents(false) to hide the table cells.  Maybe just hide the table cells either way is good enough.

Greg

Hi Greg!

 

Thanks for your reply.  This is what I'd like to do, but from what it seems the Object clipboard functions described under "Miscellaneous Object Functions," namely copyHier and pasteDown, only work when copying and pasting objects within the same module.  Attempting to copy an object from Module A and paste it into Module B gives an error message about not copying within the same module.  It appears that the only way to copy objects across modules is by dragging and dropping with the mouse.  Notably, right clicking an object and hitting "Copy" in Module A, then right clicking an object in Module B doesn't work: the "Paste" command is grayed out.

 

If you know how to work around this that would be awesome!  I'm a good way through my coding to copy all table cells one by one into a newly created table, but it's probably going to be a huge pain and take a ton of time to make sure all of the cell formatting and dimensions are copied correctly and I'd like to avoid having to go through that verification and debugging process.

 

Thanks again for the help,

Ben

Re: Copying a Table with DXL
llandale - Tue Aug 06 12:55:08 EDT 2013

I think if the orginal table has some cells missing your approach to create a table X-by-Y won't work correctly.  I'd be tempted to create the hierarchy either [1] one cell at a time with "appendCell/appendRow", or [2] one object at a time (row last-below the table, cell last-below the row) then convert the hierarchy with "toTable(oTable)".  Either way you must keep three finger pointers to the original table (one to current table, current row, current cell object) and 3 corresponding finger pointers to the new table.

You also have table properties to deal with, cell boarders, deleted (not purged) cells and rows, and of course default table attribute (displayed).  Yuuuck.

-Louie

Re: Copying a Table with DXL
brh2113 - Tue Aug 06 14:17:33 EDT 2013

llandale - Tue Aug 06 12:55:08 EDT 2013

I think if the orginal table has some cells missing your approach to create a table X-by-Y won't work correctly.  I'd be tempted to create the hierarchy either [1] one cell at a time with "appendCell/appendRow", or [2] one object at a time (row last-below the table, cell last-below the row) then convert the hierarchy with "toTable(oTable)".  Either way you must keep three finger pointers to the original table (one to current table, current row, current cell object) and 3 corresponding finger pointers to the new table.

You also have table properties to deal with, cell boarders, deleted (not purged) cells and rows, and of course default table attribute (displayed).  Yuuuck.

-Louie

I've managed to write working code to copy tables, but only when the table is rectangular (i.e., every row has the same number of cells).  I'm doing it basically with your [1] approach, except instead of creating new cells I'm copying all attributes into newly created empty cells as I iterate over the cells in each table.  If I get time I know how to go back and make it work for arbitrarily shaped tables, but from what I can tell I always have rectangular tables in my use cases so I'll probably leave it that way for now. 

 

I'm still surprised there isn't a copyTable(Table src, Object location) function built into the API that's capable of copying tables across modules, especially since that functionality exists with the mouse drag-and-drop.  Oh well. 

Re: Copying a Table with DXL
sekrbo - Wed Aug 28 08:49:49 EDT 2013

brh2113 - Tue Aug 06 14:17:33 EDT 2013

I've managed to write working code to copy tables, but only when the table is rectangular (i.e., every row has the same number of cells).  I'm doing it basically with your [1] approach, except instead of creating new cells I'm copying all attributes into newly created empty cells as I iterate over the cells in each table.  If I get time I know how to go back and make it work for arbitrarily shaped tables, but from what I can tell I always have rectangular tables in my use cases so I'll probably leave it that way for now. 

 

I'm still surprised there isn't a copyTable(Table src, Object location) function built into the API that's capable of copying tables across modules, especially since that functionality exists with the mouse drag-and-drop.  Oh well. 

Tools->Functions->Copy Objects... (copyobjs.dxl) seems to be able to copy tables. I filtered out a table and used the function to copy the display set to another module.

You might be able to work something out from that code :)

/sekrbo